package com.salon.server.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.salon.server.entity.Beautician;
import com.salon.server.model.R;
import com.salon.server.model.request.BeauticianProjectRequest;
import com.salon.server.model.request.BeauticianRequest;
import com.salon.server.service.BeauticianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/salon/beautician")
public class BeauticianController {

    @Autowired
    private BeauticianService beauticianService;

    @RequestMapping("/page")
    public R page(@RequestBody BeauticianRequest beauticianRequest) {

        return R.success(beauticianService.page(beauticianRequest, new LambdaQueryWrapper<Beautician>()
                .eq(beauticianRequest.getStatus() != null, Beautician::getStatus, beauticianRequest.getStatus())
                .like(StrUtil.isNotEmpty(beauticianRequest.getName()), Beautician::getName, beauticianRequest.getName())
                .like(StrUtil.isNotEmpty(beauticianRequest.getPosition()), Beautician::getPosition, beauticianRequest.getPosition())));
    }

    /**
     * 查询关联项目
     */
    @RequestMapping("/project")
    public R project(@RequestBody Beautician beautician) {

        return R.success(beauticianService.project(beautician));
    }

    /**
     * 更新美容师关联的项目
     */
    @PostMapping("/updateProject")
    public R updateProject(@RequestBody BeauticianProjectRequest beauticianProjectRequest) {

        beauticianService.updateProject(beauticianProjectRequest);
        return R.success();
    }

    /**
     * list
     */
    @GetMapping("/list")
    public R list() {

        return R.success(beauticianService.list());
    }

    @PostMapping("update")
    public R update(@RequestBody Beautician beautician) {

        return R.success(beauticianService.updateById(beautician));
    }

}
